using TMPro;
using UnityEngine;

public class WorldNumber : MonoBehaviour
{
    [SerializeField] private float _life;

    private bool _running;
    private ITween _tween;
    private Color _color;

    public TextMeshPro TextMesh { get; private set; }

    public string Text
    {
        get => TextMesh.text;
        set => TextMesh.text = value;
    }

    public Color Color
    {
        get => TextMesh.color;
        set => TextMesh.color = value;
    }

    private void Awake()
    {
        TextMesh = GetComponentInChildren<TextMeshPro>();
        _tween = GetComponent<ITween>();
    }

    public void Play()
    {
        _running = true;
        _tween.Play();
    }

    public void Stop()
    {
        _running = false;
        Destroy(gameObject);
    }

    private void Update()
    {
        if (!_running)
        {
            return;
        }

        if (_life > 0f)
        {
            _life -= Time.deltaTime;
            if (_life <= 0f)
            {
                _tween.Stop();
                Stop();
            }
        }
    }
}
